package cn.lishiyuan.algorithm.queue;

import cn.lishiyuan.algorithm.list.LinkedList;

/**
 * 链式队列
 * @param <T>
 */
public class LinkedQueue<T> implements LeeQueue<T>{

    LinkedList<T> list ;

    public LinkedQueue() {
        list = new LinkedList<>();
    }

    @Override
    public int count() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void enqueue(T data) {
        list.addLast(data);
    }

    @Override
    public T dequeue() {
        if (list.isEmpty()){
            return null;
        }
        T t = list.get(0);
        list.removeFirst();
        return t;
    }

    @Override
    public String toString() {
        return list.toString();
    }
}
